﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace LumenLiquid_Tool
{
    /// <summary>
    /// Interaktionslogik für MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private Backdrop _backdrop;

        private Backdrop Backdrop
        {
            get { return _backdrop; }
            set { _backdrop = value; }
        }

        public MainWindow()
        {
            InitializeComponent();
        }

        private void German_MouseButtonDown(object sender, MouseButtonEventArgs e)
        {

        }

        private void English_MouseButtonDown(object sender, MouseButtonEventArgs e)
        {

        }

        private void SidePanel_MouseEnter(object sender, MouseEventArgs e)
        {
            var enlarge = (Storyboard)FindResource("OpenSidepanel");
            enlarge.Begin();
            var close = (Storyboard)FindResource("CloseSidepanel");
            close.Stop();
        }

        private void SidePanel_MouseLeave(object sender, MouseEventArgs e)
        {
            var close = (Storyboard)FindResource("CloseSidepanel");
            close.Begin();
            var enlarge = (Storyboard)FindResource("OpenSidepanel");
            enlarge.Stop();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            SidePanelColumn.Width = new GridLength(30);
            NavGrid.NavigateTo("StartUp", NavigationGridAnimation.EDirection.Up, new Duration(new TimeSpan(0)));

            _backdrop = (Backdrop)DataContext;

            int index = 0;
            foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.NeutralCultures))
            {
                _backdrop.Languages.Add(ci);

                if (Equals(ci.EnglishName, "English"))
                    index = _backdrop.Languages.Count - 1;
            }

            cbx_PrimaryLanguage.SelectedIndex = index;

            CommandBindings.Add(Backdrop.AddProfessionCommand);
            CommandBindings.Add(Backdrop.RemoveProfessionCommand);
            CommandBindings.Add(Backdrop.AddSkillCommand);
            CommandBindings.Add(Backdrop.RemoveSkillCommand);

        }

        private void Tutorial_MouseDown(object sender, RoutedEventArgs routedEventArgs)
        {
            NavGrid.NavigateTo("ContentPanel");
            MainNavigation.NavigateTo("Tutorial", NavigationGridAnimation.EDirection.Up, new Duration(new TimeSpan(0)));
            TippsPanel.Show();
        }

        private void NewProject_MouseDown(object sender, RoutedEventArgs e)
        {
            NavGrid.NavigateTo("ContentPanel", NavigationGridAnimation.EDirection.Up);
            MainNavigation.NavigateTo("NewProject", NavigationGridAnimation.EDirection.Up, new Duration(new TimeSpan(0)));
            TippsPanel.HideInstant();
        }

        private void MainMenu_Click(object sender, RoutedEventArgs e)
        {
            NavGrid.NavigateTo("StartUp", NavigationGridAnimation.EDirection.Right);
        }

        private void MainNavigation_ScreenChanged(object sender, RoutedEventArgs e)
        {
            Header.Text = Application.Current.TryFindResource(MainNavigation.CurrentPanel + ".Header") as string;

            try
            {
                TippsPanel.DisplayText =
                    Application.Current.FindResource(MainNavigation.CurrentPanel + ".Tipp") as string;
                TippsPanel.Show();
            }
            catch (Exception)
            {
                TippsPanel.Hide();
            }
        }

        private void StartAsisstant_Click(object sender, RoutedEventArgs e)
        {
            SidePanel.IsHitTestVisible = true;
        }

        private void SidePanel_Selected(object sender, RoutedEventArgs e)
        {
            MainNavigation.NavigateTo((string)((TreeViewItem)e.Source).Tag);
        }
    }
}
